package week1;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;

import javax.swing.text.DefaultEditorKit;
import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
import java.util.Scanner;
import java.util.StringTokenizer;

public class LinkedListOfnumber {

    public static void main(String[] args) {
        String a, b;
        int number;
        String[] numner;
        Scanner scan = new Scanner(System.in);
        Scanner scan1 = new Scanner(System.in);
        System.out.println("请输入一个整数");
        number = scan.nextInt();

        Integer Head = new Integer(number);
        ;


        System.out.println("是否继续输入y/n");
        b=scan1.nextLine();
        while(b.equalsIgnoreCase("y"))
        {  Scanner scan3 = new Scanner(System.in);
            Scanner scan4 = new Scanner(System.in);
            System.out.println("请您输入一个整数");
            number = scan3.nextInt();
            Integer number1 = new Integer(number);
            Insert(Head, number1);
            System.out.println("是否继续输入Y/n");
            b = scan4.nextLine();
        }

        Integer number2 = new Integer(1);
        Integer number3 = new Integer(2);


        System.out.println();
        Head=HeadInsert(Head,number2 );
        PrintLinkedList(Head);
        System.out.println();

        PrintLinkedList(Head);
        System.out.println();
        Insert(Head,number3,2);
        PrintLinkedList(Head);
        System.out.println();
        SelectSort(Head);
        PrintLinkedList(Head);


    }

    public static void PrintLinkedList(Integer Head) {
        Integer node = Head;
        while (node != null) {
            System.out.println(node.number);
            node = node.next;
        }
    }

    public static void Insert(Integer Head, Integer node) {

        Integer node1;
        if (Head == null)
            Head = node;
        else {
            node1 = Head;
            while (node1.next != null)
                node1 = node1.next;
            node1.next = node;
        }

    }

    public static Integer Insert(Integer Head, Integer node, int number) {
        Integer node1 = Head;
        Integer node2 = Head.next;
        if (number == 1) {
            node.next = Head;
            Head = node;
            return Head;
        }
        for (int a = 2; a < number; a++) {
            node1 = node1.next;
            node2 = node2.next;
        }
        node1.next = node;
        node.next = node2;
        return Head;
    }

    public static Integer HeadInsert(Integer Head, Integer node) {
        node.next = Head;
        Head = node;
        return Head;
    }









    public static void SelectSort(Integer Head) {
Integer list=Head;
int ANT;
while(list!=null)
{
    Integer list1=list.next;
    while(list1!=null)
    {
        if(list1.number<list.number){
            ANT=list.number;
            list.number=list1.number;
            list1.number=ANT;
        }
        list1=list1.next;
    }
    list=list.next;
        }
    }}




           //number为要插入的节点的位置依次为1,2,3……，将头插入并入此项



